import React from 'react';
import PropTypes from 'prop-types';
import {
	addTodo
} from '../actions';

const AddTodo = ({
	dispatch
}) => {
	let input;
	return (
		<form 
			onSubmit = {(e)=>{
				e.preventDefault();
				if(input.value.trim()){
					dispatch(addTodo(input.value))
					input.value='';
				}
			}}
		>
			<input ref={node =>input = node} />
			<button type="submit">AddTodo</button>
		</form>
	)
}
AddTodo.propTypes = {
	dispatch: PropTypes.func.isRequired
}

export default AddTodo